using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tank : MonoBehaviour
{
    public float speed = 10f; // 前进速度
    public float reverseSpeed = 5f; // 倒车速度
    public float rotationSpeed = 100f; // 旋转速度

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        // 获取输入
        float moveDirection = Input.GetAxis("Vertical");   // 前进或倒车
        float rotationDirection = Input.GetAxis("Horizontal"); // 左右转向

        // 根据前进或倒车方向设置速度
        float currentSpeed = (moveDirection > 0) ? speed : reverseSpeed;

        // 移动小车
        transform.Translate(Vector3.forward * moveDirection * currentSpeed * Time.deltaTime);

        // 转向小车
        if (moveDirection != 0)
        {
            float rotation = rotationDirection * rotationSpeed * Time.deltaTime * (moveDirection > 0 ? 1 : -1);
            transform.Rotate(Vector3.up, rotation);
        }

    }
}